<template>
  <div>
    <el-dialog
      class="base-dialog system-user-dialog"
      :custom-class="'panna-dialog_big'"
      :append-to-body="true"
      :title="dataList.ProgrammeDetail"
      align="center"
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      @closed="closeDialog"
    >
      <div>
        <DeviceVerificationView :id.sync="id" ref="DeviceVerificationView">
        </DeviceVerificationView>
      </div>

      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="Export">{{
          dataList.Export
        }}</el-button>
        <el-button @click="cancel">{{ btn.Cancel }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import DeviceVerificationView from "./DeviceVerificationView.vue";
import { export_json_to_excel } from "@/vendor/Export2Excel";
import { getList } from "../../../api/DeviceVerification";
export default {
  name: "DeviceVerificationViewDialog",
  components: { DeviceVerificationView },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
    id: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      // tHeader: [
      //   "设备编号",
      //   "设备名称",
      //   "型号规格",
      //   "核查对象",
      //   "核查方式",
      //   "核查方法",
      // ],
      filterVal: [
        "num",
        "name",
        "specifications",
        "verificationObject",
        "verificationWay",
        "verificationMethod",
      ],
      listData: [],
      pagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
      from: {
        num: "",
        name: "",
        preparedName: "",
        preparedDate: "",
        remark: "",
      },
    };
  },
  computed: {
    btn() {
      return this.$t("ModuleDevice.buttons");
    },
    dataList() {
      return this.$t("ModuleDevice.Device");
    },
  },
  watch: {},
  created() {},
  methods: {
    export_json_to_excel,
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          return v[j];
        })
      );
    },
    // 导出
    Export() {
      getList({ id: this.id }, { pageIndex: 1, pageSize: 1 }).then((res) => {
        var list = [];
        for (
          let i = 0;
          i < res.data.dataList[0].deviceVerificationInfoDtoList.length;
          i++
        ) {
          list.push({
            num: res.data.dataList[0].deviceVerificationInfoDtoList[i].deviceDto
              .num,
            name: res.data.dataList[0].deviceVerificationInfoDtoList[i]
              .deviceDto.name,
            specifications:
              res.data.dataList[0].deviceVerificationInfoDtoList[i].deviceDto
                .specifications,
            verificationObject:
              res.data.dataList[0].deviceVerificationInfoDtoList[i]
                .verificationObject,
            verificationWay:
              res.data.dataList[0].deviceVerificationInfoDtoList[i]
                .verificationWay,
            verificationMethod:
              res.data.dataList[0].deviceVerificationInfoDtoList[i]
                .verificationMethod,
          });
        }
        var data = this.formatJson(this.filterVal, list);

        const tHeader = [
          this.dataList.DeviceNumber,
          this.dataList.DeviceName,
          this.dataList.DeviceSpecifications,
          this.dataList.InspectionTarget,
          this.dataList.InspectionMethod,
          this.dataList.InspectionProcedure,
        ];
        export_json_to_excel({
          header: tHeader, // 表头
          data, // 数据
          filename: this.dataList.InspectionPlanList, // 导出文件名
          autoWidth: true, // 导出宽度自动
          bookType: "xlsx", // 导出后缀
        });
      });
    },
    cancel() {
      this.$emit("update:dialogFormVisible", false);
    },
    closeDialog() {
      this.$parent.getList();
      this.cancel();
    },
  },
};
</script>
<style scoped>
table {
  border-collapse: collapse; /* 合并边框，使其一致 */
  width: 100%;
}
table,
th,
td {
  border: 1px solid gainsboro; /* 设置边框的样式 */
  padding: 8px; /* 可选：设置单元格的内边距 */
}
td {
  text-align: center; /* 水平居中对齐 */
  vertical-align: middle; /* 垂直居中对齐 */
}
#styled-table2 tr:first-child {
  background-color: ghostwhite;
}

#styled-table td:nth-child(1),
#styled-table td:nth-child(3) {
  background-color: ghostwhite;
}
</style>
